home *** CD-ROM | disk | FTP | other *** search
/ Language/OS - Multiplatform Resource Library / LANGUAGE OS.iso / oper_sys / emerald / emrldsys.lha / Language / Compiler / Builtins / phoney_OutStream.m < prev    next >
Encoding:
Text File  |  1990-08-16  |  1.6 KB  |  58 lines

  1. % @(#)phoney_OutStreamX    1.2  3/16/88
  2. %
  3. export _OutStreamObject to "Builtins"
  4.  
  5. const _OutStreamObject == immutable object _OutStreamObject
  6.   export getSignature, create
  7.  
  8.   const OutStreamType == type OutStreamType
  9.     operation putChar [Character]
  10.     operation putInt [Integer, Integer]
  11.     operation putReal [ Real ]
  12.     operation putString [ String ]
  13.     operation flush
  14.     operation close
  15.   end OutStreamType
  16.  
  17.   function getSignature -> [ r : Signature ]
  18.     r <- OutStreamType
  19.   end getSignature
  20.  
  21.   operation create [ fd : Integer ] -> [r : OutStreamType]
  22.     r <- object aUnixOutStreamType
  23.       export putChar, putInt, putReal, putString, flush, close
  24.       const myfd : Integer == fd
  25.       monitor
  26.     var isClosed : Boolean <- false
  27.  
  28.     operation putChar [r : Character]
  29.       if isClosed then returnAndFail end if
  30.       primitive "UnixStreamPutChar" [] <- [myfd, r]
  31.     end putChar
  32.  
  33.     operation putInt [number : Integer, width : Integer]
  34.       if isClosed then returnAndFail end if
  35.       primitive "UnixStreamPutInt" [] <- [myfd, number, width]
  36.     end putInt
  37.     operation putReal [r : Real]
  38.       if isClosed then returnAndFail end if
  39.       primitive "UnixStreamPutReal" [] <- [myfd, r]
  40.     end putReal
  41.     operation putString [r : String]
  42.       if isClosed then returnAndFail end if
  43.       primitive "UnixStreamPutString" [] <- [myfd, r]
  44.     end putString
  45.     operation flush
  46.       if isClosed then returnAndFail end if
  47.       primitive "UnixStreamFlush" [] <- [myfd]
  48.     end flush
  49.     operation close
  50.       if isClosed then returnAndFail end if
  51.       isClosed <- true
  52.     end close
  53.       end monitor
  54.     end aUnixOutStreamType
  55.   end create
  56. end _OutStreamObject
  57.